<!--隔离设备-->
<template>
  <div class="current-page">
    <!-- <div class="search-area" style="position:relative">
      <div class="search-form">
        <el-form label-width="80px" :model="searchForm">
          <el-row>
            <el-col :span="10">
              <el-form-item label="事件等级">
                <el-select v-model="searchForm.level" placeholder="请选择">
                  <el-option label="紧急" value="0"> </el-option>
                  <el-option label="报警 " value="1"> </el-option>
                  <el-option label="错误 " value="2"> </el-option>
                  <el-option label="关键 " value="3"> </el-option>
                  <el-option label="警告  " value="4"> </el-option>
                  <el-option label="通知 " value="5"> </el-option>
                  <el-option label="信息" value="6"> </el-option>
                  <el-option label="调试" value="7"> </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="事件结果">
                <el-select v-model="searchForm.result" placeholder="请选择">
                  <el-option label="成功" value="成功"> </el-option>
                  <el-option label="失败" value="失败"> </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="发生时间">
                <el-date-picker v-model="operateTime" type="daterange" range-separator="-" start-placeholder="开始日期"
                  end-placeholder="结束日期" style="width:95%;" clearable :editable="false"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="5" style="float:right">
              <el-button type="primary" @click="querySubmit">查询</el-button>
              <el-button type="primary" @click="ResetClick">重置</el-button>
            </el-col>
          </el-row>
        </el-form>
      </div>

    </div> -->
    <div>
      <div class="search-btn">
        <el-button style="margin-bottom: 10px; float: right; padding-right: 20px" type="text" icon="el-icon-refresh"
          @click="querySubmit">刷新
        </el-button>
      </div>
    </div>
    <com-table :tableData="tableData.slice((pageNum - 1) * pageSize, pageNum * pageSize)" url="sjrz/log/adminopt"
      method="get" :has-data="hasData" keyName="LogAdminOper" :table-head-list="tableHeadList" :total-count="totalCount"
      :page-num="pageNum" :page-size="pageSize" :page-sizes="pageSizes" :table-loading="loading"
      :table-height="tableHeight" :is-show-select="false" :page-show="false" :handle-show="false" :merge-flag="false"
      @setSearchHeight="setSearchHeight" @openDialog="openDialog" @getTabpation="getTabpation" ref="comTable">
    </com-table>
    <div class="pagination-container">
    <el-pagination background :current-page.sync="pageNum" :page-sizes="pageSizes" :page-size="pageSize"
      layout="total,sizes,prev,pager,next,jumper" :total="totalCount" @size-change="handleSizeChange"
      @current-change="handleCurrentChange">
    </el-pagination>
    </div>
  </div>
</template>
<script>
import ComTable from "../../components/table/comTable";
export default {
  name: "cmf_tplate",
  data() {
    return {
      pageSizes: [5, 10, 20, 50, 100],
      hasData: true,
      dialogControl: false,
      dialogTitle: "",
      tableHeadList: [
        { columnComment: "日志唯一标识", columnName: "UUID", colHidden: true },
        { columnComment: "登录用户", columnName: "LoginUser" },
        { columnComment: "责任人Id", columnName: "EmpId", colHidden: true },
        { columnComment: "责任人名称", columnName: "EmpName" },
        { columnComment: "部门名称", columnName: "DeptName" },
        {
          columnComment: "部门全称",
          columnName: "FullDeptName",
          colHidden: true,
        },
        { columnComment: "IP地址", columnName: "IP" },
        { columnComment: "日志生成时间", columnName: "OpTime" },
        { columnComment: "日志内容", columnName: "Content" },
      ],
      pageNum: 1,
      pageSize: 10,
      totalCount: 0,
      boolean: [],
      tableData: [], // 表格数据
      tableHeight: "", // 表格高度
      loading: false, // 数据加载状态遮罩
      tableDataSelected: [],
      operateTime: [],
      xproPath: "",
      searchForm: {
        warnState: "",
        warnRank: "",
        warnContent: "",
        objType: "",
      },
      infoForm: {
        from: "本地",
      },
      attrData: [],
      rules: {
        // 表单验证规则
        name: [{ required: true, trigger: "blur", message: "请输入名称" }],
      },
      emwCheckList: [],
    };
  },
  components: {
    ComTable,
  },
  created() {
    this.setTableHeight();
    this.datalist();
  },
  methods: {
    // refreshTable() {
    //   if (this.hasData) {
    //     this.getTableData(this.pageNum, this.pageSize);
    //   } else {
    //     // 调用子组件中的getTableData
    //     this.$refs.comTable.getTableData();
    //   }
    // },
    datalist() {
      // this.$get(
      //   `/sjrz/log/adminopt?page=${this.pageNum}&count=${this.pageSize}`
      // ).then((res) => {
      // console.log(res);
      // let datlit = res.data.data;
      // var array = [];
      // datlit.forEach((item) => {
      //   array.push(item.Root.LogAdminOper);
      // });
      // this.tableData = array;
      this.tableData = []
      let adminObj = JSON.parse(
        window.localStorage.getItem("administratorLog")
      );
      adminObj.forEach((item) => {
        this.tableData.push(item);
      });
      this.totalCount = this.tableData.length;
      // });
    },
    querySubmit() {
      this.datalist();
    },
    ResetClick() {
      this.searchForm = {};
      this.operateTime = [];
    },
    // getTabpation(pageNum, pageSize) {
    //   console.log(pageNum, pageSize)
    //   this.pageNum = pageNum
    //   this.pageSize = pageSize
    //   this.datalist();
    // },
    handleSizeChange(val){
      this.pageSize = val
    },
    handleCurrentChange(val){
      this.pageNum = val
      // this.datalist();
    },
    //重新加载表格
    setSearchHeight() {
      //搜索区域高度
      if (this.$refs.search !== undefined) {
        this.$nextTick(() => {
          let searchHeight = this.$refs.search.offsetHeight;
          this.setTableHeight(searchHeight);
        });
      }
    },
    //关闭表单
    dialogClosed() {
      this.infoForm = {
        name: "",
        ip: "",
        port: "",
        type: [],
        from: "本地",
      };
    },

    /**
     * 设置表格的高度
     */
    setTableHeight() {
      let clientHeiht =
        window.innerHeight || document.documentElement.clientHeight;
      this.tableHeight = clientHeiht - 250;
    },
    headerCellStyle({ row, column, rowIndex, columnIndex }) {
      return {
        "font-size": "14px",
        "font-weight": 600,
        color: "#606266",
      };
    },
    //查询
    //todo 待后台接口
    search() { },

    //新建与修改
    openDialog(type, row) {
      this.dialogControl = true;
      console.log(type);
      if (type === "add") {
        this.dialogTitle = "新增应用资源";
      } else if (type === "update") {
        this.dialogTitle = "修改应用资源";
        console.log(row, "row");
        let form = JSON.parse(JSON.stringify(row));
        console.log(form, "qqqq");
        (this.xproPath = form.XPRO_PATH),
          (this.infoForm = {
            name: form.name,
            uuid: form.uuid,
            ip: form.ip,
            port: form.port,
            type: [],
            from: "本地",
          });
        if (form.type.length > 0) {
          form.type.forEach((item) => {
            this.infoForm.type = item.XPRO_PATH;
          });
        }
      }
    },

    /**
     * 新增
     */
    addTerminal() {
      this.$refs.infoForm.validate((flag) => {
        if (flag) {
          let params = {};
          for (let item in this.infoForm) {
            if (this.infoForm[item]) {
              if (item == "type") {
                if (this.infoForm[item].length !== 0) {
                  console.log(item, this.infoForm[item], "item789");
                  params[item] = [this.infoForm[item]];
                }
              } else {
                params[item] = this.infoForm[item];
              }
            }
          }
          console.log(params);
          this.loading = true;
          this.$postForJson("app", params).then((jsonData) => {
            this.dialogControl = false;
            this.loading = false;
            let datas = jsonData.data;
            if (!datas.success) {
              this.publicModal.$emit("tips", {
                show: true,
                publicModalMessage: datas.msg,
                fontIcon: "errorWarning",
              });
              return false;
            }
            this.$message({
              message: "新增文本文件信息成功！",
              type: "success",
            });
            this.refreshTable();
            this.dialogClosed();
          });
        }
      });
    },

    /**
     * 修改
     */
    modifyTerminal() {
      this.$refs.infoForm.validate((flag) => {
        if (flag) {
          let params = {};
          for (let item in this.infoForm) {
            if (this.infoForm[item]) {
              if (item == "type") {
                if (this.infoForm[item].length !== 0) {
                  console.log(item, this.infoForm[item], "item789");
                  params[item] = [this.infoForm[item]];
                }
              } else {
                params[item] = this.infoForm[item];
              }
            }
          }
          let url = this.xproPath;
          this.loading = true;
          console.log(params, "params");
          this.$postForJson(url, params).then((jsonData) => {
            this.dialogControl = false;
            this.loading = false;
            let datas = jsonData.data;
            if (!datas.success) {
              this.publicModal.$emit("tips", {
                show: true,
                publicModalMessage: datas.msg,
                fontIcon: "errorWarning",
              });
              return false;
            }
            this.$message({
              message: "修改文本文件信息成功",
              type: "success",
            });
            this.refreshTable();
            this.dialogClosed();
          });
        }
      });
    },
    //重置
    clearData() {
      this.searchForm = {};
    },
  },
};
</script>
<style scoped>
@import "../../assets/css/treeAndTable.css";
@import "../../assets/css/commonTable";

.view {
  position: relative;
  left: 190px;
}

.title-left {
  display: inline-block;
  font-weight: 600;
  margin-left: 20px;
  margin-top: 7px;
}

.right {
  float: right;
  margin-right: 20px;
}

.block {
  text-align: center;
  margin-right: 20px;
  margin-top: 10px;
}

.checkTitle {
  width: 164px;
  height: 16px;
}

.importOrgInfo {
  cursor: pointer;
  color: #101fec;
  text-decoration: underline;
}

.importBody {
  display: flex;
  align-items: center;
  flex-grow: 1;
}

.seamless-warp {
  height: 250px;
  overflow: hidden;
}

.importIcon {
  font-size: 52px;
  width: 90px;
  text-align: center;
}

.new-search-area .btn-area .el-button {
  margin-bottom: 10px;
}

.hstyle {
  color: lightskyblue;
  margin: 10px;
  border-bottom: 1px solid #999;
}

.pstyle {
  margin-left: 25px;
  cursor: pointer;
}

.rightStyle {
  /* padding-left: 5px; */
  border: 1px solid rgb(235, 238, 245);
  border-radius: 5px;
}

ul {
  padding-inline-start: 25px;
}

ul li {
  list-style-type: none;
  line-height: 25px;
  font-size: 15px;
}

ul li:hover {
  color: lightskyblue;
  cursor: pointer;
}

.active {
  color: lightskyblue;
}

.butt {
  margin-left: 116px !important;
  margin-top: 22px;
  margin-bottom: 20px;
}

.page {
  position: absolute;
  bottom: 63px;
  left: 900px;
}
.page-table .pagination-container {
  padding-top: 10px;
  text-align: center;
}
</style>
